From 4be9201e8c34104b15ac2eda6b8c3092d7baa191 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 11 Feb 2008 09:45:36 +0000 Subject: [PATCH] xentrace: Fix bug in logic for bytes_to_wrap in trace buffer. Admittedly, the bug could only be manifest with much larger trace records than are currently allowed (or equivalently, much smaller trace buffers), but the old code was harder to read, and thus hid the logic bug well, too. Signed-off-by: Michael A Fetterman --- xen/common/trace.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/xen/common/trace.c b/xen/common/trace.c index 9af70798bb..d2f8fceeae 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -425,25 +425,18 @@ void __trace_var(u32 event, int cycles, int extra, unsigned char *extra_data) total_size += bytes_to_wrap; bytes_to_wrap = data_size; } - else - { - bytes_to_wrap -= LOST_REC_SIZE; - if ( bytes_to_wrap == 0 ) - bytes_to_wrap = data_size; - } total_size += LOST_REC_SIZE; + bytes_to_wrap -= LOST_REC_SIZE; + + /* LOST_REC might line up perfectly with the buffer wrap */ + if ( bytes_to_wrap == 0 ) + bytes_to_wrap = data_size; } if ( rec_size > bytes_to_wrap ) { total_size += bytes_to_wrap; - bytes_to_wrap = data_size; } - else - { - bytes_to_wrap -= rec_size; - } - total_size += rec_size; /* Do we have enough space for everything? */ @@ -466,14 +459,12 @@ void __trace_var(u32 event, int cycles, int extra, unsigned char *extra_data) insert_wrap_record(buf, LOST_REC_SIZE); bytes_to_wrap = data_size; } - else - { - bytes_to_wrap -= LOST_REC_SIZE; - /* LOST_REC might line up perfectly with the buffer wrap */ - if ( bytes_to_wrap == 0 ) - bytes_to_wrap = data_size; - } insert_lost_records(buf); + bytes_to_wrap -= LOST_REC_SIZE; + + /* LOST_REC might line up perfectly with the buffer wrap */ + if ( bytes_to_wrap == 0 ) + bytes_to_wrap = data_size; } if ( rec_size > bytes_to_wrap ) -- 2.30.2